/*
 Ortho2dCamera.cs

 Author:
    Anton Grigoryev <anton.grigorjev@gmail.com>

 Copyright (c) 2011 Anton Grigoryev
*/

using UnityEngine;

namespace FwtUnityEngine
{
    [RequireComponent(typeof(Camera))]
    internal class Ortho2DCamera : MonoBehaviour
    {
        [SerializeField]
        private bool uniform = true;
        [SerializeField]
        private bool autoSetUniform = true;

        public void Awake()
        {
            camera.orthographic = true;

            if (uniform)
                SetUniform();
        }

        public void LateUpdate()
        {
            if (autoSetUniform && uniform)
                SetUniform();
        }

        public void SetUniform()
        {
            var orthographicSize = camera.pixelHeight / 2;
            if (orthographicSize != camera.orthographicSize)
                camera.orthographicSize = orthographicSize;
        }
    }
}